package controller

import (
	"errors"
	"github.com/gin-gonic/gin"
	"strconv"
)
const CtxtUserIDKey="userID"

var ErrorUserNotLogin = errors.New("用户未登录")
// GetCurrentUserID 获取当前用户登录的ID
func GetCurrentUserID(c *gin.Context) (userID int64, err error) {
	uid, ok := c.Get(CtxtUserIDKey)
	if !ok {
		err = ErrorUserNotLogin
		return
	}
	userID, ok = uid.(int64)
	if !ok {
		err = ErrorUserNotLogin
		return
	}
	return
}

func getPageInfo(c *gin.Context)(int64,int64){
	//获取分页参数
	pageStr:=c.Query("page")
	SizeStr:=c.Query("size")
	var(
		page int64
		size int64
		err error
	)
	page,err=strconv.ParseInt(pageStr,10,64)
	if err!=nil{
		page=0
	}
	size,err=strconv.ParseInt(SizeStr,10,64)
	if err!=nil{
		size=0
	}
	return  page,size
}